      subroutine H5PartOutput

        include 'param.fi'
        include 'common.fi'
        include 'H5PartF.h'
      
        integer*8 file_id, status, npoints, i, timestep
        Real*8 ttmp(NTOT3T), tmpDual(GridDual2)
!        Real*8 mmatrix(NTOT3T,4)
!        integer i4
!        Real mtmp(2,2)

      Character*40 FM

      Call STATISTICS1

      Write(*,*) "WRITING RESULTS ..."
      FM = 'res                 '
      CALL CONCATI5(FM, iSTEP)
      
        ! this enables level 4 ("debug") messages to be
        ! printed by the H5Part library
        ! (4_8 is the literal for an integer*8 with value 4)
        status = h5pt_set_verbosity_level (0_8)
      
        ! open the a file called 'test.h5' in parallel for writing
        file_id = h5pt_opena ('Output.h5part')
        !file_id = h5pt_openw (FM)
      
        ! in the Fortran API, steps start at 1
        timestep = iSTEPOut
        status = h5pt_setstep (file_id, timestep)
      
        ! write an attribute to the file
C        status = h5pt_writefileattrib_string
C     &           (file_id, 'desc', 'This is a test.')
      
        ! set the size of the data array
        npoints = NTOT3T
        status = h5pt_setnpoints (file_id, npoints)
      
        ! write the data
        status = h5pt_writedata_r8 (file_id, "x", X1)
        status = h5pt_writedata_r8 (file_id, "y", X2)
        status = h5pt_writedata_r8 (file_id, "z", X3)
        status = h5pt_writedata_r8 (file_id, "U1", U1)
        status = h5pt_writedata_r8 (file_id, "U2", U2)
        status = h5pt_writedata_r8 (file_id, "U3", U3)
        status = h5pt_writedata_r8 (file_id, "Rho", RHO)
        status = h5pt_writedata_r8 (file_id, "Vortex", VORTEX)
        status = h5pt_writedata_r8 (file_id, "SheCoef", SheCoef)
        status = h5pt_writedata_r8 (file_id, "DU3DZ", DU3DZ)
        status = h5pt_writedata_r8 (file_id, "DU1DX", DU1DX)
        status = h5pt_writedata_r8 (file_id, "DPDZ", DPDZ)
!        Do I4 = 1, NTOT3T
!          Call GradCorrM1(I4, mtmp)
!          mmatrix(I4, 1) = mtmp(1,1)
!          mmatrix(I4, 2) = mtmp(1,2)
!          mmatrix(I4, 3) = mtmp(2,1)
!          mmatrix(I4, 4) = mtmp(2,2)
!        Enddo
!        status = h5pt_writedata_r8 (file_id, "M11", mmatrix(1,1))
!        status = h5pt_writedata_r8 (file_id, "M12", mmatrix(1,2))
!        status = h5pt_writedata_r8 (file_id, "M21", mmatrix(1,3))
!        status = h5pt_writedata_r8 (file_id, "M22", mmatrix(1,4))

        Do I = 1, NTOT3T
          ttmp(I) = ShapeP(I, 3) / ShapeP(I, 1)
        Enddo
        status = h5pt_writedata_r8 (file_id, "ShapeCoef", ttmp)
      
        ! close the file
        status = h5pt_close (file_id)

      
      If (ifDual.EQ.1) Then
        status = h5pt_set_verbosity_level (0_8)
        file_id = h5pt_opena ('Dual.h5part')
        timestep = iSTEPOut
        status = h5pt_setstep (file_id, timestep)
        npoints = GridDual2
        status = h5pt_setnpoints (file_id, npoints)
      
        ! write the data
        status = h5pt_writedata_r8 (file_id, "x", X1Dual)
        Do I = 1, GridDual2
          tmpDual(I) = 0.0
        Enddo
        status = h5pt_writedata_r8 (file_id, "y", tmpDual)
        status = h5pt_writedata_r8 (file_id, "z", X3Dual)
        status = h5pt_writedata_r8 (file_id, "U1", U1Dual)
        status = h5pt_writedata_r8 (file_id, "U3", U3Dual)
        status = h5pt_writedata_r8 (file_id, "Rho", RHODual)
        status = h5pt_writedata_r8 (file_id, "P", PDual)
        status = h5pt_close (file_id)
      Endif
      
      end subroutine
      
